<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags"%>

<sec:authentication property="principal" var="currentPrincipal" scope="page" />

<div class="modal-dialog x-modal-dialog" style="width: 600px;">

	<div class="modal-content">

		<div class="modal-header x-breadcrumb clearfix">

			<h2>
				<i class="glyphicon glyphicon-fire" title=""></i>&nbsp;&nbsp;<span>课程入系统</span>
			</h2>

			<button type="button" class="close" data-dismiss="modal">&times;</button>

		</div>

		<form class="form-horizontal" method="POST" action="${ctx.host}/card-orders/create-card" data-validate="true">

			<c:if test="${currentPrincipal.siteManager or currentPrincipal.siteServer}">
				<input type="hidden" name="siteId" value="${currentPrincipal.site.id}">
			</c:if>

			<div class="modal-body">
				<c:if test="${currentPrincipal.root or currentPrincipal.admin or currentPrincipal.areaServer or currentPrincipal.areaManager}">
					<div class="form-group x-form-group">
						<label class="col-xs-3 control-label">门店</label>
						<div class="col-xs-7" style="width: 60%;">
							<select name="siteId" class="form-control" data-validate="required">
								<c:forEach var="site" items="${persist.getSites(currentPrincipal.id)}">
									<option value="${site.id}">${site.name}</option>
								</c:forEach>
							</select>
						</div>
					</div>
				</c:if>
				<div class="form-group x-form-group">
					<label class="col-xs-3 control-label">产品</label>
					<div class="col-xs-7" style="width: 60%;">
						<select name="productId" class="form-control select2" data-validate="required">
							<option value="MONTH_CARD">月卡</option>
							<option value="SEASON_CARD">季卡</option>
							<option value="YEAR_CARD">年卡</option>
						</select>
					</div>
				</div>
				<div class="form-group x-form-group">
					<label class="col-xs-3 control-label">用户手机</label>
					<div class="col-xs-7">
						<input type="text" class="form-control" name="mobile" data-validate="required|mobile" value="${param.mobile}" />
					</div>
				</div>
				<div class="form-group x-form-group">
					<label class="col-xs-3 control-label">验证码</label>
					<div class="col-xs-4">
						<input type="text" class="form-control" name="code" data-validate="required" /> <input type="hidden" class="form-control" name="token" />
					</div>
					<div class="col-xs-3">
						<button type="button" id="get-code" class="btn btn-primary form-control" style="height: 32px; padding: 0 .85rem;">获取验证码</button>
					</div>
				</div>
				<div class="form-group x-form-group">
					<label class="col-xs-3 control-label">姓名</label>
					<div class="col-xs-7">
						<input type="text" class="form-control" name="name" data-validate="required" value="${param.name}" />
					</div>
				</div>
				
				<%-- <c:if test="${currentPrincipal.root or currentPrincipal.admin}"> --%>
				<div class="form-group x-form-group">
          <label class="col-xs-3 control-label">用户渠道</label>
          <div class="pull-left col-xs-7">
            <c:set value="${persist.listUserSourceTypeParent()}" var="typeParent" ></c:set>
            <c:set value="${persist.listUserSourceTypeChildren()}" var="typeChildrenMap" ></c:set>
            <select name="userSourceType" class="form-control" data-validate="required">
            
              <c:forEach var="typeParentItem" items="${typeParent}">
                <optgroup label="${typeParentItem.name}">
                  <c:choose>
                    <c:when test="${not empty typeChildrenMap[typeParentItem.id.toString()]}">
                      <c:forEach var="childrenTypes" items="${typeChildrenMap[typeParentItem.id.toString()]}">
                        <c:if test="${currentPrincipal.siteManager or currentPrincipal.siteServer}">
                          <c:choose>
                            <c:when test="${not empty childrenTypes.sites}">
                              <c:if test="${childrenTypes.sites.contains(currentPrincipal.site.code)}">
                                <option value="${childrenTypes.id}">${typeParentItem.name}-${childrenTypes.name}</option>
                              </c:if>
                            </c:when>
                            <c:otherwise>
                              <option value="${childrenTypes.id}">${typeParentItem.name}-${childrenTypes.name}</option>
                            </c:otherwise>
                          </c:choose>
                        </c:if>
                        <c:if test="${currentPrincipal.root or currentPrincipal.admin or currentPrincipal.areaServer or currentPrincipal.areaManager}">
                          <option value="${childrenTypes.id}">${typeParentItem.name}-${childrenTypes.name}</option>
                        </c:if>
                        
                      </c:forEach>
                    </c:when>
                    <c:otherwise>
                      <option value="${typeParentItem.id}">${typeParentItem.name}</option>
                    </c:otherwise>
                  </c:choose>
                </optgroup>
              </c:forEach>
            </select>
          </div>
        </div>
        <%-- </c:if> --%>
				
				<div class="form-group x-form-group">
					<label class="col-xs-3 control-label">优惠券码</label>
					<div class="col-xs-7">
						<input type="text" class="form-control" name="couponCode" />
					</div>
				</div>
			</div>

			<div class="modal-footer">
				<button type="submit" class="btn btn-success btn-shadow btn-shadow-success x-btn">确定</button>
				&nbsp;&nbsp;&nbsp;&nbsp;
				<button type="button" class="btn btn-default btn-shadow btn-shadow-default x-btn" data-dismiss="modal">取消</button>
			</div>
		</form>
	</div>
</div>
